package org.algorithm.落雪.数组.二月;

import com.sun.tools.javac.util.Assert;
import org.junit.Test;

/**
 * good luck guys
 * keep learning for algorithm
 *
 */
public class 两数之和 {

    @Test
    public  void test() throws  Exception {
        int[] arr={2,3,4,8,5,5};
        int[] ints = twoSum(arr, 6);
        Assert.check(ints[0]==0 && ints[1]==2);
    }

    public  int[] twoSum(int[] arr,int target){
        int length = arr.length;
        for (int i = 0; i< length; i++){
            for (int j = i+1; j < length; j++){
                if (arr[i] + arr[j] == target){
                    int[] result = new int[2];
                    result[0] = i;
                    result[1] = j;
                    return result;
                }
            }
        }
        return null;
    }

}
